package com.itheima;

import org.testng.annotations.Test;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

/**
 * @ProjectName: shixun DaErXia
 * @Titile: TreeMapDemo
 * @Author: 雨
 * @Description: TODO
 */
public class TreeMapDemo {
    public static void main(String[] args) {
        test1();
        test2();
    }
    public static void test2(){//方法名小写
        TreeMap<Student,String> treeMap=new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()-o1.getAge();
            }
        });

        treeMap.put(new Student("小赵",18),"北京");
        treeMap.put(new Student("小王",21),"天津");
        treeMap.put(new Student("小李",18),"杭州");
        treeMap.put(new Student("小张",19),"成都");
        treeMap.put(new Student("小q",18),"北京");
        treeMap.put(new Student("小钱",20),"湖南");
        treeMap.forEach((k,v)-> System.out.println(k+":"+v));
    }
    @Test
    private  static void test1(){
        TreeMap<Student,String> treeMap=new TreeMap<>();
        treeMap.put(new Student("小赵",18),"北京");
        treeMap.put(new Student("小王",21),"天津");
        treeMap.put(new Student("小李",18),"杭州");
        treeMap.put(new Student("小张",19),"成都");
        treeMap.put(new Student("小q",18),"北京");
        treeMap.put(new Student("小钱",20),"湖南");
        treeMap.forEach((k,v)-> System.out.println(k+":"+v));

        HashMap<String,String> hashMap=new HashMap<>();

    }
}
